/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.game.poker;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import extension.game.database.Database;
import extension.game.database.UserData;
import log.Debug;

/**
 *
 * @author daz
 */
public class RoomInfoHandler extends BaseClientRequestHandler {

    @Override
    public void handleClientRequest(User user, ISFSObject params) {
        //get extension
        PokerRoomExtension parent = (PokerRoomExtension) getParentExtension();
        PokerGame pokerGame = parent.getPokerGame();
        //room info
        int isPlay = (pokerGame.getIsPlay() ? 1 : 0);
        if (!Debug.isDebug) {
            Database database = parent.getDatabase();
            UserData userData = database.getUserInfo(user.getName());
            user.setProperty(PokerFlag.PLAYER_MONEY, userData.getMoney());
            parent.getResponse().sendRoomInfo(isPlay, pokerGame.getPotAmount(), pokerGame.getCommunityCard(),
                    pokerGame.getBettingTurn(), pokerGame.getMoneyJoinMin(), pokerGame.getMoneyJoinMax(),
                    userData.getName(), userData.getMoney(), userData.getLevel(), userData.getLevelName(),
                    user);
        } else {
            user.setProperty(PokerFlag.PLAYER_MONEY, 1000000000l);
            parent.getResponse().sendRoomInfo(isPlay, pokerGame.getPotAmount(), pokerGame.getCommunityCard(),
                    pokerGame.getBettingTurn(), pokerGame.getMoneyJoinMin(), pokerGame.getMoneyJoinMax(),
                    user.getName(), 10000, 0, "Nongdan",
                    user);
        }
    }
}
